

****FIRST 25 PORTFOLIOS AND LAST COLUMN (EVERYTHING BUT THE LAST ROW)***
est clear

use "$jfqa_rep/20_Stock_Setup.dta", clear

qui{
gen accel=ret-first_10
	
foreach i in accel futret convexity_split  {
	drop if missing(`i')
}

drop if year<1963
drop if year==1963 & month<6

drop if year>2022
drop if year==2022 & month==12

*convexity split rank
gen convex_five=.
sort monthyear convexity_split
by monthyear: replace convex_five=1 if _n<_N/5
by monthyear: replace convex_five=2 if _n>=_N/5 & _n<_N/5*2
by monthyear: replace convex_five=3 if _n>=_N/5*2 & _n<_N/5*3 
by monthyear: replace convex_five=4 if _n>=_N/5*3 & _n<_N/5*4
by monthyear: replace convex_five=5 if _n>=_N/5*4

*accel rank
gen accel_five=.
sort monthyear accel
by monthyear: replace accel_five=1 if _n<_N/5
by monthyear: replace accel_five=2 if _n>=_N/5 & _n<_N/5*2
by monthyear: replace accel_five=3 if _n>=_N/5*2 & _n<_N/5*3 
by monthyear: replace accel_five=4 if _n>=_N/5*3 & _n<_N/5*4
by monthyear: replace accel_five=5 if _n>=_N/5*4

egen convex_ret=group(convex_five accel_five)

replace futret=futret*100

egen vw_raw=wtmean(futret), weight(mktcap) by(monthyear convex_ret)

sort convex_ret monthyear 
collapse vw_raw, by(convex_ret monthyear)

tsset convex_ret monthyear  

**FIRST 5 x 5 PORTFOLIOS
forval i=1/25 {
	eststo: newey vw_raw if convex_ret ==`i', lag(6)
}

**LAST COLUMN
sort monthyear convex_ret
keep if convex_ret==1 | convex_ret==5 | convex_ret==6 | convex_ret==10 | convex_ret==11 | convex_ret==15 | convex_ret==16 | convex_ret==20 | convex_ret==21 | convex_ret==25

gen vw_raw_dif=vw_raw-vw_raw[_n+1] if convex_ret==1 | convex_ret==6 | convex_ret==11 | convex_ret==16 | convex_ret==21

sort convex_ret monthyear 
foreach i in 1 6 11 16 21 { 
	eststo: newey vw_raw_dif if convex_ret ==`i', lag(6)
}
}


****LAST ROW***
use "$jfqa_rep/20_Stock_Setup.dta", clear

qui{
gen accel=ret-first_10
	
foreach i in accel futret convexity_split  {
	drop if missing(`i')
}

drop if year<1963
drop if year==1963 & month<6

drop if year>2022
drop if year==2022 & month==12

*convexity split rank
gen convex_five=.
sort monthyear convexity_split
by monthyear: replace convex_five=1 if _n<_N/5
by monthyear: replace convex_five=2 if _n>=_N/5 & _n<_N/5*2
by monthyear: replace convex_five=3 if _n>=_N/5*2 & _n<_N/5*3 
by monthyear: replace convex_five=4 if _n>=_N/5*3 & _n<_N/5*4
by monthyear: replace convex_five=5 if _n>=_N/5*4

*return rank
gen accel_five=.
sort monthyear accel
by monthyear: replace accel_five=1 if _n<_N/5
by monthyear: replace accel_five=2 if _n>=_N/5 & _n<_N/5*2
by monthyear: replace accel_five=3 if _n>=_N/5*2 & _n<_N/5*3 
by monthyear: replace accel_five=4 if _n>=_N/5*3 & _n<_N/5*4
by monthyear: replace accel_five=5 if _n>=_N/5*4

egen convex_ret=group(accel_five convex_five)

replace futret=futret*100

egen vw_raw=wtmean(futret), weight(mktcap) by(monthyear convex_ret)

collapse vw_raw, by(convex_ret monthyear)

sort monthyear convex_ret

keep if convex_ret==1 | convex_ret==5 | convex_ret==6 | convex_ret==10 | convex_ret==11 | convex_ret==15 | convex_ret==16 | convex_ret==20 | convex_ret==21 | convex_ret==25

*average difference returns
gen vw_raw_dif=vw_raw-vw_raw[_n+1] if convex_ret==1 | convex_ret==6 | convex_ret==11 | convex_ret==16 | convex_ret==21

sort  convex_ret monthyear
tsset convex_ret monthyear
foreach i in 1 6 11 16 21 { 
	eststo: newey vw_raw_dif if convex_ret ==`i', lag(6)
}
}

esttab using "$jfqa_rep/Table_IA7.csv", nostar replace b(2)
